<div class="flex flex-col border-l border-1 border-slate-800 pl-3">
    <div class="py-2 flex justify-between">
        <div class="text-2xl font-bold text-slate-100"><%= @organizations |> Page.title("organization") %></div>
        <%= render AzimuttWeb.PartialsView, "_page_search.html", page: @organizations %>
    </div>

    <div class="align-middle shadow sm:rounded-sm">
        <table class="w-full text-left">
            <thead class="text-gray-100 bg-slate-800 text-xs font-semibold">
                <tr>
                    <th class="group p-1" scope="col">
                        Created at
                        <%= render AzimuttWeb.PartialsView, "_page_sort.html", page: @organizations, key: "created_at" %>
                    </th>
                    <th class="group p-1" scope="col">
                        Name
                        <%= render AzimuttWeb.PartialsView, "_page_sort.html", page: @organizations, key: "name" %>
                    </th>
                    <th class="p-1" scope="col">Plan</th>
                    <th class="p-1" scope="col">
                        <span title="members">M</span> /
                        <span title="projects">P</span> /
                        <span class="group" title="is_personal">
                            NP
                            <%= render AzimuttWeb.PartialsView, "_page_sort.html", page: @organizations, key: "is_personal" %>
                        </span></th>
                    <th class="p-1" scope="col">Created by</th>
                    <th class="p-1" scope="col">Data</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-slate-800 text-slate-500 bg-slate-900">
                <%= for organization <- @organizations.items do %>
                    <tr class="text-xs whitespace-nowrap hover:bg-slate-800 hover:text-slate-300">
                        <td class="group p-1">
                            <%= format_datetime(organization.created_at) %>
                            <%= render AzimuttWeb.PartialsView, "_page_filter.html", page: @organizations, key: "created_at", value: format_date_filter(organization.created_at) %>
                        </td>
                        <td class="p-1">
                            <%= link to: Routes.admin_organization_path(@conn, :show, organization), class: "underline" do %>
                                <%= img_tag(organization.logo, class: "inline-block h-4 w-4 rounded-md") %>
                                <%= organization.name %>
                            <% end %>
                        </td>
                        <td class="p-1">
                            <%= organization.plan %>
                            <%= if organization.stripe_customer_id do %>
                                <%= link "Stripe", to: StripeSrv.customer_url(organization.stripe_customer_id), target: "_blank", class: "underline" %>
                            <% end %>
                            <%= if organization.clever_cloud_resource do %>
                                <span title={organization.clever_cloud_resource.owner_name}>Clever Cloud</span>
                            <% end %>
                            <%= if organization.heroku_resource do %>
                                <span title={organization.heroku_resource.name}>Heroku</span>
                            <% end %>
                        </td>
                        <td class="group p-1">
                            <span title="members"><%= display_number(organization.members) %></span> /
                            <span title="projects"><%= display_number(organization.projects) %></span> /
                            <%= if organization.is_personal do %>
                                <span class="text-scheme-blue" title="Personal">Y</span>
                            <% else %>
                                <span class="text-scheme-yellow" title="Non personal">N</span>
                            <% end %>
                            <%= render AzimuttWeb.PartialsView, "_page_filter.html", page: @organizations, key: "is_personal", value: organization.is_personal |> to_string() %>
                        </td>
                        <td class="group p-1" title={"Created on #{format_datetime(organization.created_at)}"}>
                            <%= link to: Routes.admin_user_path(@conn, :show, organization.created_by), class: "underline" do %>
                                <%= img_tag(organization.created_by.avatar, class: "inline-block h-4 w-4 rounded-md") %>
                                <%= organization.created_by.name %>
                            <% end %>
                            <%= render AzimuttWeb.PartialsView, "_page_filter.html", page: @organizations, key: "created_by_id", value: organization.created_by_id %>
                        </td>
                        <td class="p-1 truncate max-w-xs" title={organization.data |> format_data()}><%= organization.data |> format_data() %></td>
                    </tr>
                <% end %>
            </tbody>
        </table>
    </div>

    <%= render AzimuttWeb.PartialsView, "_pagination.html", page: @organizations %>
</div>
